{{ extend './common/layout.html' }}

{{ block 'main' }}

{{ include './common/header.html' }}
<!-- 主体内容 -->
<div class="content">
    {{ include './common/aside.html' }}
    <div class="main">
        <!-- 分类标题 -->
        <div class="title">
            <h4>用户</h4>
            <span>找到1个用户</span>
            <a href="/admin/user/add" class="btn btn-primary new">新增用户</a>
        </div>
        <!-- /分类标题 -->
        <!-- 内容列表 -->
        <table class="table table-striped table-bordered table-hover custom-table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>邮箱</th>
                    <th>角色</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {{ each users v }}
                <tr>
                    <td>{{ v._id + '' }}</td>
                    <td>{{ v.uname }}</td>
                    <td>{{ v.email }}</td>
                    <td>{{ { 'admin': '超级管理员', 'normal': '普通用户' }[v.role] }}</td>
                    <td>{{ [ '禁用', '启用' ][v.status] }}</td>
                    <td>
                        <a href="/admin/user/edit/{{ v._id + '' }}" class="glyphicon glyphicon-edit"></a>
                        <i class="delUserBtn glyphicon glyphicon-remove" data-toggle="modal"
                            data-target=".confirm-modal" data-id="{{ v._id + '' }}"></i>
                    </td>
                </tr>
                {{ /each }}
            </tbody>
        </table>
        <!-- /内容列表 -->
        <!-- 分页 -->
        <ul class="pagination">
            {{ if page > 1 }}
            <li><a href="/admin/user/list?page={{ page - 1 }}"><span>&laquo;</span></a></li>
            {{ /if }}
            <% for (var i = 1; i <= pages; i ++) { %>
            <li><a href="/admin/user/list?page={{ i }}">{{ i }}</a></li>
            <% } %>
            {{ if page < pages }}
            <li><a href="/admin/user/list?page={{ page - 0 + 1 }}"><span>&raquo;</span></a></li>
            {{ /if }}
        </ul>
        <!-- /分页 -->
    </div>
</div>
<!-- /主体内容 -->
<!-- 删除确认弹出框 -->
<div class="modal fade confirm-modal">
    <div class="modal-dialog modal-lg">
        <form class="modal-content" action="/admin/user/del" method="get">
            <input type="hidden" name="id" id="delUserId">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span>&times;</span></button>
                <h4 class="modal-title">请确认</h4>
            </div>
            <div class="modal-body">
                <p>您确定要删除这个用户吗?</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <input type="submit" class="btn btn-primary" value="确认">
            </div>
        </form>
    </div>
</div>
<!-- /删除确认弹出框 -->

{{ /block }}


{{ block 'js' }}

<script>
    $(() => {
        $('.delUserBtn').click((e) => {

            // $(e.target).attr('data-id')
            // $(e.target).data('id')

            $('#delUserId').val(e.target.dataset.id)

        })
    })
</script>

{{ /block }}